script_enemy_main{

let radius=270;
let xpos=0;
let ypos=0;
let lastpop=0;

let shot1=0;
let bullet1=[];
let shot2=0;
let bullet2=[];

let character="Takeo";
let cutin=character;
let dispelled=0;
let spellcards=6;
let spellcardnumber=28;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshots7=("\script\SoundEffects\shots7.wav");
let SEshotm6=("\script\SoundEffects\shotm6.wav");
let SEshotm8=("\script\SoundEffects\shotm8.wav");

let BG1=("\script\Images\BackgroundLayers\Takeo3.png");
let GRboss=("\script\Images\CharacterSprites\Takeo.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsTakeo1.txt");

	LoadSE("\script\SoundEffects\shots7.wav");
	LoadSE("\script\SoundEffects\shotm6.wav");
	LoadSE("\script\SoundEffects\shotm8.wav");

	LoadGraphic("\script\Images\CharacterSprites\Takeo.png");
	LoadGraphic("\script\Images\BackgroundLayers\Takeo3.png");

	SetScore(300000);
	SetLife(350);
	SetTimer(50);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=6; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("[Foam Party] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}


if(frame==60){ xpos=GetPlayerX; ypos=GetPlayerY; }
if(frame>=60 && frame<150){
	loop(2){
	let angle=rand(0,360);
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,xpos+radius*cos(angle),ypos+radius*sin(angle));
	Obj_SetAngle(shot1,rand(0,360));
	Obj_SetSpeed(shot1,rand(0.1,0.4));
	ObjShot_SetDelay(shot1,20);
	ObjShot_SetGraphic(shot1,rand_int(6,7));
	Obj_SetCollisionToObject(shot1,true);
	bullet1=bullet1~[shot1];
	}
if(time%4==0){ PlaySE(SEshots7); }
radius-=2;
}
if(time>=60 && time%5==0){
	let angle=270+rand(-90,90);
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,cx+rand(-180,180),maxy+20);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,rand(0.2,0.4));
	ObjShot_SetDelay(shot1,20);
	ObjShot_SetGraphic(shot1,rand_int(4,5));
	Obj_SetCollisionToObject(shot1,true);
	bullet1=bullet1~[shot1];
}
if(frame==240 && time>=150){
let angle=-37.5;
	loop(4){
	shot2=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot2,GetX,GetY);
	Obj_SetAngle(shot2,GetAngleToPlayer+angle);
	Obj_SetSpeed(shot2,4);
	ObjShot_SetBombResist(shot2,true);
	ObjShot_SetGraphic(shot2,15);
	Obj_SetCollisionToObject(shot2,true);
	bullet2=bullet2~[shot2];
	angle+=25;
	}
PlaySE(SEshotm8);
usespell=-30;
}
if(frame==240 || OnPlayerMissed==true){ frame=50; radius=270; }


let i=0;
while(i<length(bullet2)){
	if(Obj_BeDeleted(bullet2[i])){
	bullet2=erase(bullet2,i);
	i--;
	}
i++;
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i);
	i--;
	}
	else{
	let h=0;
		while(h<length(bullet2)){
			if(Collision_Obj_Obj(bullet2[h],bullet1[i])==true){
			let random=rand_int(0,1);
				if(random==0){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),rand(-0.1,-1.25),rand(-0.3,-1),0.01,0.025,0,rand(3.5,4.5),rand_int(30,31),0); }
				if(random==1){ CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),rand(0.1,1.25),rand(-0.3,-1),-0.01,0.025,0,rand(3.5,4.5),rand_int(30,31),0); }
			Obj_Delete(bullet1[i]);
			if(lastpop<=0){ PlaySE(SEshotm6); lastpop=5; }
			}
		h++;
		}
	}
i++;
}
if(lastpop>0){ lastpop--; }


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss2X",GetX); SetCommonData("Boss2Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0,300,280);
	SetGraphicScale(1.6,1.6);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
//	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}